﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SearchEngine.DAO;
using SearchEngine;
using System.Collections.Generic;

namespace ClientSide
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SearchOperations s = new SearchOperations(1, 20);

            #region temp
            //GridView1.DataSource = s.GetAllRoutes(DateTime.Now);

            //GridView1.AutoGenerateColumns = false;


            //BoundField c1 = new BoundField();
            //c1.DataField = "FullRoute";
            //GridView1.Columns.Add(c1);

            //BoundField c2 = new BoundField();
            //c2.DataField = "trsList";
            //GridView1.Columns.Add(c2);
            //GridView1.Columns[2].Visible = false;
            //GridView1.Columns[0].Visible = false;

            //CommandField c3 = new CommandField();
            //c3.ButtonType = ButtonType.Button;
            //GridView1.Columns.Add(c3);

            //GridView1.DataBind();
            #endregion

            for (int i = 0; i < s.GetAllRoutes(DateTime.Now).Count; i++)
            {
                GridViewBinding(s.GetAllRoutes(DateTime.Now).ElementAt(i), i);
            }
        }

        void btnRedirect_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://www.yhoo.com");
        }

        private void GridViewBinding(Route r, int i)
        {
            //GridView gv = new GridView();

            List<TimedRoadSegment> trs = r.trsList;
            Panel p = new Panel();
            int counter = 0;
            foreach (TimedRoadSegment t in trs)
            {
                HtmlGenericControl div = new HtmlGenericControl("div");
                div.Attributes["class"] = "div";
                Label lbl = new Label();
                lbl.ID = i + "dLbl" + counter;
                lbl.Text = t.StartHour.ToString();
                div.Controls.Add(lbl);
                p.Controls.Add(div);
                counter++;
            }
            Button btn = new Button();
            btn.Text = "Резервирай";
            btn.ID = "btn" + i;
            btn.CssClass = "btn";

            HtmlGenericControl divBtn = new HtmlGenericControl("div");
            divBtn.Attributes["class"] = "divBtn";
            divBtn.Controls.Add(btn);

            p.Controls.Add(divBtn);

            btn.Click += new EventHandler(btn_Click);
 
            Repeater1.Controls.Add(p);
        }

        void btn_Click(object sender, EventArgs e)
        {
            ControlCollection contolList = ((sender as Button).Parent.Parent.Controls)[0].Controls;
            lblProba.Text = (contolList[0] as Label).Text;
        }
    }
}
